function setUp(){
	
	$('#createAccountLink').bind('click', function(){
		getFragment("createAccount", function(data){
			$("#createAccount").html(data);
			$('#createForm').show('fast');
			
			$('#PBcreateAccount').bind('click', function(){
				// Check to see if the user has entered information in all of the fields.
				
				emptyFields = Array();
				
				$(this).parent('form').children('input[type!=button]').each(function(i){
					if( $(this).val() == "" ) emptyFields.push( $('label[for=' + $(this).attr('id') + ']' ).text().toLowerCase().slice(0, -1) );
				});
				

				if(emptyFields.length == 0){
					
					// Show progress div (also stops the user resubmitting the form)
					$('#progressDisplay').show();
				
					
					$.post(PicBoard.baseURL + 'rsrc.php?req=createAcct', $(this).parent('form').serialize(), function(data){
						
						if(data.statusCode == 200){
							$('#createAccount').html("<h3>Account Created!</h3><p>We have sent an email to the account you have provided with an activation link. After activating you can log in above.</p>");
						
						} else {
							alert(data.message);
						}
						
						$('#progressDisplay').hide();
					}, 'json');
					
				} else {
					// User has not filled in all the fields.
					alert("Please fill in the following fields:" + emptyFields.join(", "));				
				}
			});
		});
	});
	
	
	$('#resetPassword').bind('click', function(){
		getFragment("resetPassword", function(data){
			$("#createAccount").html(data);
			$('#resetForm').show('fast');
			
			$('#PBresetPassword').bind('click', function(){
				email = $('#reset_email').val();
				
				// Is the email address blank
				if( /\b[\w\.-]+@[\w\.-]+\.\w{2,4}\b/.test(email) ){
					$.post(PicBoard.baseURL + "rsrc.php?req=resetPassword", $('form#reset_form').serialize(), function(data){
						if(data.statusCode == 200){
							$('#resetForm').hide();
							alert("Password reset email sent");
						} else {
							$('#resetForm').hide();
							alert(data.message);
						}
					}, 'json');
				} else {
					// User has not entered an email address
					PicBoard.getTranslations( ['lang_196_validationNoEmail'], function(message){ alert(message.payload.lang_196_validationNoEmail) } );
				}
			});
		});
	});
	
}

function performLogin(){
	$.post(PicBoard.baseURL + "rsrc.php?req=validateLogin", $('form#loginForm').serialize(), function(data){
		if(data.statusCode == 200){
			window.location = 'home';
		} else {
			$('#errorMessage').html(data.message).show();
			return false;
		}
	}, 'json');
	
	return false;
}

PicBoard.addLoadEvent( "setUp()" );